package sc.tool.sqlgen.branchinfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.util.CollectionUtils;

public class ParseResult {
    private List<BranchInfo> successResults = new ArrayList<BranchInfo>();
    private Map<String, String> failResults = new HashMap<String, String>();

    public void addSuccessResult(BranchInfo branchInfo) {
        successResults.add(branchInfo);
    }

    public void addFailResult(String branchId, String errMessage) {
        failResults.put(branchId, errMessage);
    }

    public List<BranchInfo> getSuccessResults() {
        return successResults;
    }

    public void setSuccessResults(List<BranchInfo> successResults) {
        this.successResults = successResults;
    }

    public Map<String, String> getFailResults() {
        return failResults;
    }

    public void setFailResults(Map<String, String> failResults) {
        this.failResults = failResults;
    }

    @Override
    public String toString() {
        int totalCount = successResults.size() + failResults.size();
        String resultMessage = "共解析[" + totalCount + "]笔记录，成功[" + successResults.size() + "]笔，失败[" + failResults.size()
                + "]";

        StringBuilder sb = new StringBuilder(resultMessage);
        sb.append("\n");

        int showFailCount = 10;
        if (!CollectionUtils.isEmpty(failResults)) {
            for (String branchId : failResults.keySet()) {
                if (showFailCount-- > 0) {
                    sb.append(failResults.get(branchId)).append("\n");
                } else {
                    break;
                }
            }
        }
        return sb.toString();

    }

}
